import type { orderlistData, searchListQuery, BuyAgainResData, AdddressData } from '@/types/order'
import type { ResultParams } from '@/types/global'
import { http } from '@/utils/http'

export default {
  getOrderList: (params: searchListQuery) => {
    //获取订单列表数据
    return http<ResultParams<orderlistData>>({
      method: 'GET',
      url: '/v1/shop/order/searchListForShop',
      data: {
        company_id_: 1,
        is_item_list_: true,
        ...params,
      },
    })
  },
  // 删除订单
  delOrderById: (id_: number) => {
    return http<null>({
      method: 'GET',
      url: `/v1/shop/order/markNotViewForShop/${id_}`,
      data: {},
    })
  },
  // 再来一单添加商品合并到购物车
  buyAgain: (jsonStr: string) => {
    return http<BuyAgainResData>({
      method: 'POST',
      url: `/v1/shop/cart/mergeCartForWeb`,
      data: {
        jsonStr: jsonStr,
      },
    })
  },

  getOrderByIdApi: (id: number) => {
    return http<orderlistData>({
      method: 'GET',
      url: `/v1/shop/order/getById/${id}`,
    })
  },
  orderCancelApi: (data: any) => {
    return http<orderlistData>({
      method: 'POST',
      url: `/v1/shop/order/cancel`,
      data: data,
    })
  },
  getAddressListApi: () => {
    return http<AdddressData[]>({
      method: 'GET',
      url: `/v1/shop/address/listByLoginUser`,
    })
  },
  saveAddressApi: (data: AdddressData) => {
    return http<any>({
      method: 'POST',
      url: `/v1/shop/address/save`,
      header: {
        'Content-Type': 'application/json;charset=utf-8',
      },
      data: data,
    })
  },
}
